/**
 * Created by jocky on 19/09/2017.
 */
var moneyObj = {
    /**
     * 历史记录
     */
    history: function (type, direction) {
        //显示loading
        show_loading_table('money_history_table', 3);

        var params = {};
        params.isRender = 2;//ajax调用

        var pageNo_dom = 'money_history_pageNo';
        var pageTotal_dom = 'money_history_pageTotal';
        params.pageNo = getPageNo(pageNo_dom, pageTotal_dom, type, direction);

        var formObj = $('#money_history_form');
        $.each(formObj.find('input,select'), function (i, v) {
            var name = $.trim($(v).attr('name'));
            if (name != '') {
                params[name] = $(v).val();
            }
        });

        $.getJSON('/money/history', params, function (json) {
            var t = json;
            $("#" + pageNo_dom).val(parseInt(t.pageNo));
            $("#" + pageTotal_dom).html(parseInt(t.pageTotal));
            var sumMoney = parseFloat(t.sumMoney);
            var color = '';
            if (sumMoney > 0) {
                color = 'red';
            }
            if (sumMoney < 0) {
                color = 'green';
            }

            var tr_head = "<tr>" +
                "<td><i style='color: red;'>汇总</i></td>" +
                "<td></td>" +
                "<td class='text-right' style='color:" + color + "'>" + sumMoney + "</td>" +
                "</tr>";

            var tr = "";
            $.each(t.lists, function (i, v) {
                var money = parseFloat(v.money);
                var color = '';
                if (money > 0) {
                    color = 'red';
                }
                if (money < 0) {
                    color = 'green';
                }
                var time = convertDate(v.time, 1);
                tr += "<tr>";
                tr += "<td>" + v.direction + "</td>";
                tr += "<td class='text-center'>" + time + "</td>";
                tr += "<td class='text-right' style='color:" + color + "'>" + money + "</td>";
                tr += "</tr>";
            });

            $("#money_history_table").find('tbody').html(tr_head + tr);

            page_content_onresize();
        })
    }
};